﻿using System.Collections.Generic;

namespace HK.Editor.GUIEx.Protocol.TreeView.Data
{

    /// <summary>
    /// 事件委托 : 树视图模型变更
    /// </summary>
    public delegate void ModelChanged();
    
    /// <summary>
    /// 接口 : 表述数据容器
    /// </summary>
    /// <typeparam name="TBranch">树枝类型</typeparam>
    public interface ITableTreeDataContainer<TBranch> where TBranch : ITreeBranch
    {
        /// <summary>
        /// 根节点
        /// </summary>
        TBranch Root { get; }
        
        /// <summary>
        /// 树枝列表
        /// </summary>
        IList<TBranch> Branches { get; }

        /// <summary>
        /// 变更事件
        /// </summary>
        event ModelChanged Changed;
        
        /// <summary>
        /// 最大Id
        /// </summary>
        int MaxId { get; }
        
        /// <summary>
        /// 设置树枝列表
        /// </summary>
        /// <param name="iBranches">树枝列表</param>
        void SetBranches(IList<TBranch> iBranches);

        /// <summary>
        /// 生成唯一树枝Id
        /// </summary>
        /// <returns>唯一树枝Id</returns>
        int GenerateBranchID();

        /// <summary>
        /// 生成祖先Id列表
        /// </summary>
        /// <param name="iId">Id</param>
        /// <returns>祖先Id列表</returns>
        IList<int> GetAncestorIds(int iId);

        TBranch Find(int iId);

        IList<int> GetDescendantsThatHaveChildren(int iId);

        void MoveBranches(ITreeBranch iParent, int iInsertIndex, List<ITreeBranch> iBranches);
    }
}
